<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Auth;

/**
 * 验证权限中间件
 */
class PermissionMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if (Auth::user()->hasPermission())
            return $next($request);
        else {
            if (get("?"))
                abort("401", "无权访问！");
            else
                throwError("无权访问！");
        }
    }
}
